package cn.bonoon.entities;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import cn.bonoon.kernel.support.entities.BaseEntity;
import cn.bonoon.kernel.support.entities.EntityTree;

/**
 * 地区信息
 * 
 * @author lyq
 * 
 */
@Entity
@Table(name = "t_place")
public class PlaceEntity extends BaseEntity implements EntityTree<PlaceEntity> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4371813658787954688L;
	/**
	 * 地区编码；
	 * 12位的地区编码：省(2)+市(2)+县(2)+镇(3)+村(3) 共12位
	 */
	@Column(name = "C_CODE", length = 15)
	private String code;

	/**
	 * 19位的地区编码，
	 * 省级代码		市级代码	县级代码	乡级代码	村级代码	乡属性代码	村属性代码	城乡分类代码	备注项
	 */
	@Column(name = "C_CODE19", length = 20)
	private String code19;
	
	/**
	 * 本级编码，如：省级为：44、广州为01、荔湾区为03等
	 * 
	 */
	@Column(name = "C_LEVELCODE", length = 3)
	private String levelCode;
	
	/**
	 * <pre>
	 * 地区名的简称,如,广东简称为粤等.
	 * 注意,如果是市级,并且市级没有定义简称,则会使用上一级的简称,直接找到最近一级的简称为止.
	 * 如果都没有,则简称为空.
	 * </pre>
	 */
	@Column(name = "C_ABBNAME", length = 4)
	private String abbreviationName;
	
	
	/**
	 * 城市编码，对应车牌的城市编号。如：广州-A，深圳-B等
	 */
	@Column(name = "C_SHORTCODE", length = 4)
	private String shortCode;

	@Column(name = "C_DISABLED")
	private boolean disabled;

	/**
	 * 地区的级别，包括：国家，省（直辖市），市，区（县）、镇、村、乡等
	 * 
	 * TODO 下个版本这里应该使用枚举
	 */
	@Enumerated
	@Column(name = "C_LEVEL")
	private PlaceLevel level;

	@ManyToOne(targetEntity = PlaceEntity.class)
	@JoinColumn(name = "R_PARENT_ID")
	private PlaceEntity parent;

	@OneToMany(mappedBy = "parent", targetEntity = PlaceEntity.class)
	private List<PlaceEntity> children;
	
	@Column(name = "C_POPULATION")
	private Long population;

	/**
	 * 经度
	 */
	@Column(name = "C_LONGITUDE")
	private Double longitude;
	
	/**
	 * 纬度
	 */
	@Column(name = "C_LATITUDE")
	private Double latitude;

	/**
	 * 
	 */
	@Column(name = "C_XPATH", length = 500)
	private String xpath;
	
	@Column(name = "C_SIZE")
	private int size;

	@Column(name = "C_FULLNAME")
	private String fullName;

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public Long getPopulation() {
		return population;
	}

	public void setPopulation(Long population) {
		this.population = population;
	}

	public String getXpath() {
		return xpath;
	}

	public void setXpath(String xpath) {
		this.xpath = xpath;
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	public PlaceEntity getParent() {
		return parent;
	}

	public void setParent(PlaceEntity parent) {
		this.parent = parent;
	}

	public List<PlaceEntity> getChildren() {
		return children;
	}

	public void setChildren(List<PlaceEntity> children) {
		this.children = children;
	}

	public void setAbbreviationName(String abbreviationName) {
		this.abbreviationName = abbreviationName;
	}

	public String getAbbreviationName() {
		return abbreviationName;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public PlaceLevel getLevel() {
		return level;
	}

	public void setLevel(PlaceLevel level) {
		this.level = level;
	}

	public String getShortCode() {
		return shortCode;
	}

	public void setShortCode(String shortCode) {
		this.shortCode = shortCode;
	}

	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public String getCode19() {
		return code19;
	}

	public void setCode19(String code19) {
		this.code19 = code19;
	}

	public String getLevelCode() {
		return levelCode;
	}

	public void setLevelCode(String levelCode) {
		this.levelCode = levelCode;
	}

}
